perm([],[]).
perm(List,[H|Perm]) :- delete(H,List,Rest), perm(Rest,Perm).

% the goal we'll call from PHP:
% S is the set of which we want to compute permutations, P the list of solutions
allperms(S,P) :- findall(X, perm(S,X), P).

% starts the socket server
listen :-
	new_socket_server(Socket, localhost/9000, 50), accept_loop(Socket).

% socket server accept loop: ... -> accept -> process -> close -> ...
accept_loop(Socket) :-
	accept(Socket, _/_, ConSocket),
	read_exdr(ConSocket, Goal), Goal, write_exdr(ConSocket, Goal),
	close(ConSocket),
	accept_loop(Socket).